package com.kx.yooli.kx.wechat.controller.user;

import com.kx.yooli.kx.wechat.po.result.AjaxResult;
import com.kx.yooli.kx.wechat.po.user.UserInfo;
import com.kx.yooli.kx.wechat.service.sys.IUserService;
import com.kx.yooli.kx.wechat.utils.comm.GsonUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author john_sqwen
 * @date 2024/3/21
 * @PROJECT_NAME wechat
 * @description create LoginController by john_sqwen
 * and loginController value is
 */
@RestController
@Tag(name = "userController" ,description = "登录控制器")
@RequestMapping("/api/user/")
public class UserController {
    @Resource
    private IUserService userService;
    private final Logger log  = LoggerFactory.getLogger(UserController.class);
    @PostMapping("goLogin")
    public AjaxResult goLogin(@RequestBody String object, HttpServletRequest request){
        log.info("the json value is {},sessionId{}", (GsonUtils.gsonString(object)),request.getSession().getId());
        return userService.userGoLogin(object);
    }

    @PostMapping("goRegister")
    public AjaxResult goRegister(@RequestBody String object, HttpServletRequest request){
        log.info("the json value is {},sessionId{}", (GsonUtils.gsonString(object)),request.getSession().getId());
        return userService.goRegister(object);
    }

    @PostMapping("initInfo")
    public AjaxResult initInfo(@RequestBody String object){
        log.info("the json value is {}", object);
        return userService.initInfo(object);
    }

    /**
     * 修改用户信息
     * @param userInfo ob
     * @return com.kx.yooli.kx.wechat.po.result.AjaxResult
     */
    @PostMapping(value = "updateUserInfo",produces = MediaType.APPLICATION_JSON_VALUE)
        public AjaxResult updateUserInfo(@RequestBody UserInfo userInfo){
        log.info("params value is  {}",userInfo);
        return userService.updateUserInfo(userInfo);
    }

    @PostMapping("getUserInfo")
    public AjaxResult getUserInfo(@RequestBody String object){
        log.info("the json value is {}", object);
        return userService.getUserInfo(object);
    }
}
